package org.huawei.view;

import javafx.geometry.Insets;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.stage.Stage;

import java.net.URL;

public class SuccessView {

    public static void success(Stage stage, String message) {
        Dialog<Void> dialog = new Dialog<>();
        dialog.setTitle("成功");
        dialog.initOwner(stage);

        // 创建 VBox
        VBox vbox = new VBox();
        vbox.setPadding(new Insets(50));
        vbox.setSpacing(10);

        // 创建标签并设置样式
        Label label = new Label(message);
        VBox.setMargin(label, new Insets(150, 0, 0, 0));  // 上, 右, 下, 左
        label.setStyle("-fx-font-size: 24px; -fx-text-fill: rgb(255,255,255); -fx-font-weight: bold;");
        vbox.getChildren().add(label);

        URL imageUrl = AlartView.class.getResource("/image/background4.jpg");
        Image backgroundImage = new Image(imageUrl.toExternalForm());
        BackgroundImage background = new BackgroundImage(
                backgroundImage,
                BackgroundRepeat.NO_REPEAT,
                BackgroundRepeat.NO_REPEAT,
                BackgroundPosition.CENTER,
                new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, false, false, true, true)
        );

        // 设置背景图片
        dialog.getDialogPane().setBackground(new Background(background));
        dialog.getDialogPane().setStyle("-fx-opacity: 1.0;");
        dialog.getDialogPane().setContent(vbox);
        dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK);

        dialog.showAndWait();
    }
}
